import {
	objDeepCopy
} from "../../../../assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	methods: {
		init() {
			this.getlist(this, 1);
		},
		handleSizeChange(val) {
			var secCode = this.Model.secCode;
			var thrCode = this.Model.thrCode;
			var page = this.Model.page;
			page.pageSize = val;
			switch (this.Model.tableMsg.type) {
				case 'medium':
					this.getlist(this, 2, secCode, undefined, page);
					break;
				case 'small':
					this.getlist(this, 3, undefined, thrCode, page);
					break;
				default:
			}

		},
		handleCurrentChange(val) {
			var secCode = this.Model.secCode;
			var thrCode = this.Model.thrCode;
			var page = this.Model.page;
			page.pageIndex = val;
			switch (this.Model.tableMsg.type) {
				case 'medium':
					this.getlist(this, 2, secCode, undefined, page);
					break;
				case 'small':
					this.getlist(this, 3, undefined, thrCode, page);
					break;
				default:
			}
		},
		//获取列表数据
		getlist(that, level, productCategoryNo, classNumberInTheProduct, page) {
			var apiTest = this.apiTest;
			page = page || this.Model.page;
			this.$ajax({
				method: 'post',
				// url: '/api/saleGoodsLevel/list',
				url: apiTest + '/sale/saleGoodsLevel/list',
				data: {
					condition: {
						level: level,
						productCategoryNo: productCategoryNo, //中类请求传的参数
						classNumberInTheProduct: classNumberInTheProduct //小类请求传的参数
					},
					pageSize: page.pageSize,
					pageIndex: page.pageIndex
				}
			}).then((res) => {
				console.log(res);
				that.Model.tableData = [];
				var data = res.data;

				if (data.status == 200) {
					var obj = {};
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result.result;
					for (var i = 0; i < result.length; i++) {
						obj = objDeepCopy(result[i]);
						if (level == 1) {
							obj.level = '一级'
						} else if (level == 2) {
							obj.level = '二级'
						} else {
							obj.level = '三级'
						}

						that.Model.tableData.push(obj);
					}
					if (level == 1) {
						that.Model.largeTableData = objDeepCopy(that.Model.tableData);
					} else if (level == 2) {
						that.Model.mediumTableData = objDeepCopy(that.Model.tableData);
					} else if (level == 3) {
						that.Model.smallTableData = objDeepCopy(that.Model.tableData);
					}

				} else {

				}
			});
		},

		//点击row查看
		handleClickItem(row) {
			console.log(row)
			if (row.level == '一级') {
				console.log(row.sort);
				this.Model.tableHeaderData = objDeepCopy(this.Model.mediumTableHeader);
				this.Model.tableData = objDeepCopy(this.Model.mediumTableData);
				this.Model.tableMsg = objDeepCopy(this.Model.mediumTableMsg);
				this.Model.secCode = row.productCategoryNo;
				this.getlist(this, 2, row.productCategoryNo, undefined);
			} else if (row.level == '二级') {
				this.Model.tableHeaderData = objDeepCopy(this.Model.smallTableHeader);
				this.Model.tableData = objDeepCopy(this.Model.smallTableData);
				this.Model.tableMsg = objDeepCopy(this.Model.smallTableMsg);
				this.Model.thrCode = row.classNumberInTheProduct;
				this.getlist(this, 3, undefined, row.classNumberInTheProduct);
			} else if (row.level == '三级') {

			}
		},
		//
		//返回大类
		toLarge() {
			this.Model.tableMsg = objDeepCopy(this.Model.largeTableMsg);
			this.Model.tableHeaderData = objDeepCopy(this.Model.largeTableHeader);
			this.Model.tableData = objDeepCopy(this.Model.largeTableData);
		},
		//返回中类
		toMedium(type) {
			this.Model.tableMsg = objDeepCopy(this.Model.mediumTableMsg);
			this.Model.tableHeaderData = objDeepCopy(this.Model.mediumTableHeader);
			this.Model.tableData = objDeepCopy(this.Model.mediumTableData);
		}
	}
}
export default Controller;
